/** 
 *
 * Description: 
 *
 * @author lirong
 * @version 1.0
 * <pre>
 * Modification History: 
 * Date         Author      Version     Description 
 * ------------------------------------------------------------------ 
 * 2012-5-3    lirong       1.0        1.0 Version 
 * </pre>
 */

package com.creditease.rss.util;

import android.graphics.Bitmap;
import android.graphics.Matrix;

/**
 * 
 * Description:
 * 
 * @author lirong
 * @version 1.0
 * 
 *          <pre>
 * Modification History: 
 * Date         Author      Version     Description 
 * ------------------------------------------------------------------ 
 * 2012-5-3    lirong       1.0        1.0 Version
 * </pre>
 */

public class ThumbnailUtils {

	public static Bitmap thumbnailBitmap(Bitmap bitmapOrg, int newWidth,
			int newHeight) {
		// 加载需要操作的图片，这里是一张图片
		// 获取这个图片的宽和高
		int width = bitmapOrg.getWidth();
		int height = bitmapOrg.getHeight();

		// 计算缩放率，新尺寸除原始尺寸
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;

		// 创建操作图片用的matrix对象
		Matrix matrix = new Matrix();

		// 缩放图片动作
		matrix.postScale(scaleWidth, scaleHeight);
		// 创建新的图片
		Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
				height, matrix, true);

		bitmapOrg.recycle();
		return resizedBitmap;
	}
}
